using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.Utils;

using DevExpress.XtraEditors.Repository;

using MM.Entities;
using MM.Business;  
namespace MM
{
    public partial class frmTimPhieuDH_KetQua : Form
    {
        string _matau = "";
        string _nguoitao = "";
        string _sConn = "";

        // the delegate the subscribers must implement
        public delegate void ChonPhieuDatHang(object frmTimPhieuNK_KetQua, ChonPhieuDHEventArgs chonPDHevent);

        // an instance of the delegate
        public ChonPhieuDatHang chonPDH;

        public frmTimPhieuDH_KetQua(string sConn, List<PHIEU_DAT_HANG> lstPDH)
        {
            InitializeComponent();
            _sConn = sConn;

            this.InitGrid(lstPDH);
        }
        private void InitGrid(List<PHIEU_DAT_HANG> lstPDH)
        {
            this.gridControl1.DataSource = lstPDH;
        }

        private void lnkSoPhieuNK_Click(object sender, EventArgs e)
        {
            ColumnView col = (ColumnView)this.gridControl1.FocusedView;
            string mapdh = col.FocusedValue.ToString();


            ChonPhieuDHEventArgs pdhevent = new ChonPhieuDHEventArgs(mapdh);

            if (chonPDH != null)
            {
                chonPDH(this, pdhevent);
            }
        }

        private void gridDSVT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (gridDSVT.FocusedRowHandle >= 0)
                {
                    string mapdh = gridDSVT.GetFocusedRowCellValue("POThamChieuSAP").ToString();

                    ChonPhieuDHEventArgs pdhevent = new ChonPhieuDHEventArgs(mapdh);

                    if (chonPDH != null)
                    {
                        chonPDH(this, pdhevent);
                    }
                }
            }
        }
    }

    class ChonPhieuDHEventArgs : EventArgs
    {
        public string POThamChieuSAP = "";

        public ChonPhieuDHEventArgs(string mapdh)
        {
            POThamChieuSAP = mapdh;
        }
    }
}